package com.naizhuai.ui.adapter;

import android.content.Context;
import android.graphics.Rect;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * @author：lichenxi
 * @date 2018/3/26 17
 * email：525603977@qq.com
 * Fighting
 * LinearLayoutManager spacing
 */
public class SpacesItemDecoration extends RecyclerView.ItemDecoration {
    private static final int HORIZONTAL = 0;
    private static final int VERTICAL = 1;
    private int orientation=VERTICAL;
    private int space;

    public SpacesItemDecoration(int space) {
        this.space = space;
    }
    public SpacesItemDecoration(int space,@RecyclerView.Orientation int orientation) {
        this.space = space;
        this.orientation=orientation;
    }
    public SpacesItemDecoration(Context context,int resid, @RecyclerView.Orientation int orientation) {
        this.space = context.getResources().getDimensionPixelSize(resid);
        this.orientation=orientation;
    }
    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        outRect.left = space;
        outRect.right = space;
        outRect.bottom = space;

        // Add top margin only for the first item to avoid double space between items
        if (parent.getChildLayoutPosition(view) == 0) {
                outRect.top = space;
        } else {
            if (orientation==HORIZONTAL){
                outRect.top = space;
            }else {
                outRect.top = 0;
            }
        }
    }
}